﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace PlasmaMes
{
    public partial class MainForm : Form
    {
        Dictionary<UISymbolButton, Form> m_dicForm = new Dictionary<UISymbolButton, Form>();
        Form m_currentForm = null;
        Button m_currentButton = null;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            m_dicForm.Add(Button_主页, new Form_Auto());
            m_dicForm.Add(Button_RFID, new Form_Rfid());
            m_dicForm.Add(Button_MES, new Form_Mes());
            m_dicForm.Add(Button_PLC, new Form_PLC());
            m_dicForm.Add(Button_KyPLC, new Form_KYPLC());

            foreach (KeyValuePair<UISymbolButton, Form> kp in m_dicForm)
            {
                kp.Value.TopLevel = false;
                kp.Value.Parent = this.panel_main;
                kp.Value.AutoScroll = true;
                kp.Value.Dock = DockStyle.Fill;
            }

            Button_主页.PerformClick();
        }

        private void FormDisplay(UISymbolButton uiSymbolButton)
        {
            this.Invoke(new Action(() =>
            {
                uiSymbolButton.FillColor = Color.FromArgb(0, 192, 0);
                uiSymbolButton.FillHoverColor = Color.FromArgb(0, 192, 0);
                uiSymbolButton.FillPressColor = Color.FromArgb(0, 192, 0);
                panel_main.Controls.Clear();
                panel_main.Controls.Add(m_dicForm[uiSymbolButton]);
                m_dicForm[uiSymbolButton].Show();
            }));
                
            foreach(var btn in m_dicForm.Keys)
            {
                if(btn != uiSymbolButton)
                {
                    this.Invoke(new Action(() =>
                    {
                        btn.FillColor = Color.FromArgb(80, 160, 255);
                        btn.FillHoverColor = Color.FromArgb(80, 160, 255);
                        btn.FillPressColor = Color.FromArgb(80, 160, 255);
                    }));
                }
            }  
        }

        private void Button_RFID_Click(object sender, EventArgs e)
        {
            FormDisplay(Button_RFID);
        }

        private void Button_MES_Click(object sender, EventArgs e)
        {
            FormDisplay(Button_MES);
        }

        private void Button_PLC_Click(object sender, EventArgs e)
        {
            FormDisplay(Button_PLC);
        }

        private void Button_主页_Click(object sender, EventArgs e)
        {
            FormDisplay(Button_主页);
        }

        private void Button_KyPLC_Click(object sender, EventArgs e)
        {
            FormDisplay(Button_KyPLC);
        }
    }
}
